package com.xbongbong.saas.enums.product;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author WuHB
 * @date 2021/11/17 16:24
 */
@Getter
public enum CostAdjustProductEnum {

    // 产品
    PRODUCT(SelectProductEnum.PRODUCT.getAttr(), "enum.adjustProduct.attrName.productName", "product", FieldTypeEnum.LINK_DATA.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 基本单位
    BASIC_UNIT(SelectProductEnum.UNIT.getAttr(), "enum.adjustProduct.attrName.basicUnit", "unit", SelectProductEnum.UNIT.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 仓库
    WAREHOUSE(SelectProductEnum.WAREHOUSE.getAttr(), "enum.adjustProduct.attrName.warehouse", "warehouse", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 批次
    BATCH(SelectProductEnum.BATCH.getAttr(), "enum.adjustProduct.attrName.batch", "batch", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 1, ShowTypeEnum.ALL.getCode(), 0, 0),
    // 生产日期
    PRODUCE_DATE(SelectProductEnum.PRODUCE_DATE.getAttr(),SelectProductEnum.PRODUCE_DATE.getI18nAttrName(),SelectProductEnum.PRODUCE_DATE.getSaasAttr(),SelectProductEnum.PRODUCE_DATE.getFieldType(),SetTypeEnum.DISABLE_REPEAT.getCode(),0,0,ShowTypeEnum.ALL.getCode(),1,0),
    // 保质期
    GUARANTEE_PERIOD(SelectProductEnum.GUARANTEE_PERIOD.getAttr(),SelectProductEnum.GUARANTEE_PERIOD.getI18nAttrName(),SelectProductEnum.GUARANTEE_PERIOD.getSaasAttr(),SelectProductEnum.GUARANTEE_PERIOD.getFieldType(),SetTypeEnum.DISABLE_REPEAT.getCode(),0,0,ShowTypeEnum.ALL.getCode(),1,0),
    // 到期日期
    EXPIRE_DATE(SelectProductEnum.EXPIRE_DATE.getAttr(),SelectProductEnum.EXPIRE_DATE.getI18nAttrName(),SelectProductEnum.EXPIRE_DATE.getSaasAttr(),SelectProductEnum.EXPIRE_DATE.getFieldType(),SetTypeEnum.DISABLE_REPEAT.getCode(),0,0,ShowTypeEnum.ALL.getCode(),1,0),
    // 成本小计调整金额
    ADJUST_AMOUNT("num_20", "enum.adjustProduct.attrName.adjustAmount", "adjustAmount", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 库存数量
    STOCK(SelectProductEnum.STOCK.getAttr(), "enum.adjustProduct.attrName.stock", "stock", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.EDIT.getCode(), 1, 0),
    // 原产品成本（元）
    OLD_COST(SelectProductEnum.COST.getAttr(), "enum.adjustProduct.attrName.oldCost", "oldCost", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.EDIT.getCode(), 1, 0),
    // 新产品成本（元）
    NEW_COST("num_30", "enum.adjustProduct.attrName.newCost", "newCost", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.EDIT.getCode(), 1, 0),
    // 成本小计金额（元）
    TOTAL_COST(SelectProductEnum.TOTAL_COST.getAttr(), "enum.adjustProduct.attrName.totalCost", "totalCost", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.EDIT.getCode(), 1, 0),
    ;

    CostAdjustProductEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable, Integer editHide, Integer showType, Integer visible, Integer required) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.visible = visible;
        this.required = required;
    }

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 英文名称
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     */
    private Integer showType;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    /**
     * 获取修改时不可见的字段
     *
     * @return 修改时不可见的字段
     */
    public static List<String> getUpdataInvisibleAttrList() {
        return Arrays.asList(STOCK.getAttr(), OLD_COST.getAttr(), NEW_COST.getAttr(), TOTAL_COST.getAttr());
    }

    public static List<String> getNonEditableList() {
        return Arrays.asList(PRODUCT.getAttr(), BASIC_UNIT.getAttr(), WAREHOUSE.getAttr(), BATCH.getAttr(), ADJUST_AMOUNT.getAttr(),
                STOCK.getAttr(), OLD_COST.getAttr(), TOTAL_COST.getAttr(), PRODUCE_DATE.getAttr(), GUARANTEE_PERIOD.getAttr(), EXPIRE_DATE.getAttr());
    }

    public static String[] getProductScreen() {
        return new String[]{ProductEnum.NAME.getAttr(), ProductEnum.SERIALNO.getAttr(), ProductEnum.SPECIFICATION.getAttr(), ProductEnum.STOCK.getAttr(), ProductEnum.UNIT.getAttr()};
    }
}
